package org.dtrd.modules.archive.entity.bean.report;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveComplication;

import java.util.StringJoiner;

/**
 * <p>
 * 糖尿病并发症
 * </p>
 *
 * @author QR
 * @since 2022-01-20
 */
@Getter
@Setter
@ApiModel(value = "糖尿病并发症详情")
public class DiabetesComplicationReport {

    @ApiModelProperty("糖尿病肾病状况")
    private String nephropathyText;
    @ApiModelProperty("糖尿病肾病确诊日期")
    private String nephropathyDate = "——";
    @ApiModelProperty("糖尿病肾病数据")
    private String nephropathyData = "——";

    @ApiModelProperty("视网膜病变状况")
    private String retinopathyText;
    @ApiModelProperty("视网膜病变确诊日期")
    private String retinopathyDate = "——";
    @ApiModelProperty("视网膜病变数据")
    private String retinopathyData = "——";

    @ApiModelProperty("周围神经病变状况")
    private String peripheralText;
    @ApiModelProperty("周围神经病变确诊日期")
    private String peripheralDate = "——";
    @ApiModelProperty("周围神经病变数据")
    private String peripheralData = "——";

    @ApiModelProperty("心血管自主神经病变状况")
    private String cardiovascularText;
    @ApiModelProperty("心血管自主神经病变确诊日期")
    private String cardiovascularDate = "——";
    @ApiModelProperty("心血管自主神经病变数据")
    private String cardiovascularData = "——";

    @ApiModelProperty("消化系统自主神经病变状况")
    private String digestiveText;
    @ApiModelProperty("消化系统自主神经病变确诊日期")
    private String digestiveDate = "——";
    @ApiModelProperty("心血管自主神经病变数据")
    private String digestiveData = "——";


    @ApiModelProperty("泌尿生殖系统自主神经病变状况")
    private String genitourinaryText;
    @ApiModelProperty("泌尿生殖系统自主神经病变确诊日期")
    private String genitourinaryDate = "——";
    @ApiModelProperty("泌尿生殖系统自主神经病变数据")
    private String genitourinaryData = "——";

    @ApiModelProperty("其他自主神经病变")
    private String otherneuropathyText;
    @ApiModelProperty("其他自主神经病变名称")
    private String otherneuropathyName = "——";
    @ApiModelProperty("其他自主神经病变确诊日期")
    private String otherneuropathyDate = "——";
    @ApiModelProperty("其他自主神经病变检查项目")
    private String otherneuropathyItem = "——";

    @ApiModelProperty("糖尿病下肢血管病变状况")
    private String  extremityText;
    @ApiModelProperty("糖尿病下肢血管病变确诊日期")
    private String extremityDate = "——";
    @ApiModelProperty("糖尿病下肢血管病变状况数据")
    private String extremityData = "——";

    @ApiModelProperty("糖尿病足状况")
    private String dfootText;
    @ApiModelProperty("糖尿病足确诊日期")
    private String dfootDate = "——";
    @ApiModelProperty("糖尿病足数据")
    private String dfootData = "——";

    @ApiModelProperty("酮症酸中毒")
    private String dkaText;
    @ApiModelProperty("酮症酸中毒有确诊日期")
    private String dkaDate = "——";
    @ApiModelProperty("酮症酸中毒数据")
    private String dkaData = "——";

    @ApiModelProperty("糖尿病高渗综合症状况")
    private String hhsText;
    @ApiModelProperty("糖尿病高渗综合症确诊日期")
    @JsonFormat(pattern = Constant.TIME_PATTERN_SDF, timezone = "GMT+8")
    private String hhsDate = "——";
    @ApiModelProperty("随机血糖")
    private String hhsRandomSugar = "——";
    @ApiModelProperty("电解质Na")
    private String hhsNa = "——";
    @ApiModelProperty("电解质K")
    private String hhsK = "——";
    @ApiModelProperty("血浆渗透压")
    private String hhsOpp = "——";

    public DiabetesComplicationReport parseFromPo(DtrdEntRdArchiveComplication po) {
        // 糖尿病肾病
        Integer nephropathy = po.getNephropathy();
        if (nephropathy != null && nephropathy.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())){
            nephropathyText = Constant.DiabetesDiagnose.valueOf(nephropathy).getName();
            nephropathyDate = DateUtil.formatDate(po.getNephropathyDate());
            StringJoiner joiner = new StringJoiner(",");
            if (po.getNephropathyUrineProtein() != null) {
                joiner.add("尿蛋白：" + po.getNephropathyUrineProtein() + " g/L");
            }
            if (po.getNephropathyAcr() != null) {
                joiner.add("ACR: " + po.getNephropathyAcr() + "mg/24h");
            }
            if (po.getNephropathyGfr() != null) {
                joiner.add("CFR(Cr)：" + po.getNephropathyGfr() + "ml/min");
            }
            nephropathyData = joiner.toString();
        }
        //  其他自主神经病变
        Integer otherneuropathy = po.getOtherneuropathy();
        if (otherneuropathy != null && otherneuropathy.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())){
            otherneuropathyText = Constant.DiabetesDiagnose.valueOf(otherneuropathy).getName();
            otherneuropathyName = po.getOtherneuropathyName();
            otherneuropathyDate = DateUtil.formatDate(po.getOtherneuropathyDate());
            otherneuropathyItem = po.getOtherneuropathyItem();
        }
        Integer hhs = po.getHhs();
        if (hhs != null && hhs.equals(Constant.DiabetesDiagnose.DIAGNOSE.getType())) {
            hhsText = Constant.DiabetesDiagnose.valueOf(hhs).getName();
            hhsDate = DateUtil.formatDate(po.getHhsDate());
            if (po.getHhsRandomSugar() != null) {
                hhsRandomSugar = po.getHhsRandomSugar() + Constant.Unit.SUGAR_VALUE_UNIT;
            }
            if (po.getHhsNa() != null) {
                hhsNa = po.getHhsNa() + Constant.Unit.MMOL_L;
            }
            if (po.getHhsK() != null) {
                hhsK = po.getHhsK() + Constant.Unit.MMOL_L;
            }
            if (po.getHhsOpp() != null) {
                hhsOpp = po.getHhsOpp() + "mOsm/L";
            }
        }
        return this;
    }
}
